<template>
    <div class="wrap">
        <div class="flexWrap">
            <div class="leftWrap">
                <div class="app-button-container">
                    <el-button type="primary" @click="dialogLeftTop1_1_show()"> 新建</el-button>
                </div>
                <div class="filter-container">
                    <div class= 'filterBox'>
                    <div class='leftPart filterPart'>
                    </div>
                    <div class='rightPart filterPart'>
                        <el-input style="width: 220px;" class="filter-item" placeholder="请输入搜索条件" v-model="filter.keywords">
                        </el-input>
                        <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="getListBySearch">搜索</el-button>
                    </div>
                    </div>
                </div>
                <complexTable
                :hasSelection= false :list = 'tableList1' :totalList = 'totalList1' :theadList = "messageConst.theadList1" :operationButtons = 'messageConst.operationButtons1' :statusArr = 'messageConst.statusArr'
                @operationEvent0 = 'operationEvent1_0' @operationEvent1 = 'operationEvent1_1' @operationEvent2 = 'operationEvent1_2' @getListByPagination = 'getListByPagination'
                ></complexTable>
            </div>
          <div class="rightWrap">
            <category :options = 'options' @selectedType = 'selectedType'></category>
          </div>
        </div>
        <el-dialog  :title="dialogLeftTop1_1_title" :visible.sync="dialogLeftTop1_1" class='dialogLeftTop1_1'>
            <el-form ref="formLeftTop1" :model="formLeftTop1" label-width="80px">
                <el-form-item label="提醒类别">
                <el-select v-model="formLeftTop1.type" placeholder="请选择提醒类别" >
                    <el-option v-for = 'item in options' :label="item.label" :value="item.value" :key = 'item.value'></el-option>
                </el-select>
                </el-form-item>
                <el-form-item label="模板名称">
                    <el-input v-model ='formLeftTop1.name'></el-input>
                </el-form-item>
                <el-form-item label="内容">
                    <el-input type='textarea' rows = '10' v-model ='formLeftTop1.content'></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogLeftTop1_1 = false">取 消</el-button>
                <el-button type="primary" @click="formLeftTop1_submit()">确 定</el-button>
            </div>
        </el-dialog>
        <el-dialog  title="内容预览" :visible.sync="dialogLeftTop1_2" class='dialogLeftTop1_2'>
            <el-row>
              <el-col>
                <div>
                  <h3>名称：</h3> 
                  <p style='padding-left:20px;'>{{previewData.name}}</p>
                </div>
                </el-col>
            </el-row>
            <el-row>
              <el-col>
                 <div>
                  <h3>简介：</h3> 
                  <p style='padding-left:20px;'>{{previewData.content}}</p>
              </div>
              </el-col>
            </el-row>
        </el-dialog>
    </div>
</template>

<script>
    import waves from '@/directive/waves/index.js'
    import Tinymce from '@/components/Tinymce'
    import complexTable from '@/views/table/complexTable'
    import category from 'yimiviews/components/category'
    import { messageConst } from '@/yimiviews/knowledgeManage/columnsConst'
    import { pending, postForm, remove } from '@/api/knowledgeManage/message'
    import { dictionary } from '@/api/knowledgeManage/dictionary'
    const defaultForm = {
      type: '',
      name: '',
      content: '',
      status: ''
    }
    export default {
      directives: { waves },
      components: { category, complexTable, Tinymce },
      mounted() {
        this.initSelect()
        this.handleFilter()
      },
      data() {
        return {
          dialogLeftTop1_1: false,
          dialogLeftTop1_2: false,
          previewData: {},
          messageConst,
          tableList1: [],
          totalList1: 0,
          listQuery: {
            page: 1,
            limit: 5
          },
          filter: {
            type: '',
            keywords: ''
          },
          dialogLeftTop1_1_title: '',
          formLeftTop1: Object.assign({}, defaultForm),
          options: []
        }
      },
      methods: {
        selectedType(selected) {
          this.filter.type = selected.value
          this.listQuery.page = 1
          this.handleFilter()
        },
        initSelect() {
          dictionary({ type: 'txlb' }).then((res) => {
            this.options = res.data.list
          })
        },
        getListBySearch() {
          this.listQuery.page = 1
          this.handleFilter()
        },
        getListByPagination(listQuery) {
          console.log('分页参数')
          console.log(listQuery)
          this.listQuery = listQuery
          this.handleFilter()
        },
        handleFilter() {
          const query = Object.assign({}, this.listQuery, this.filter)
          console.log(query)
          pending(query).then(res => {
            this.tableList1 = res.data.list
            this.totalList1 = parseInt(res.data.total)
          })
        },
        formLeftTop1_submit() {
          console.log(this.formLeftTop1)
          postForm(this.formLeftTop1).then((res) => {
            this.dialogLeftTop1_1 = false
            this.$message({
              message: '恭喜你，提交成功!',
              type: 'success'
            })
            this.handleFilter(this.listQuery)
          })
        },
        dialogLeftTop1_1_show() {
          this.dialogLeftTop1_1_title = '新建'
          this.formLeftTop1 = Object.assign({}, defaultForm)
          this.dialogLeftTop1_1 = true
        },
        operationEvent1_0(row) {
          this.dialogLeftTop1_1_title = '编辑'
          this.formLeftTop1 = Object.assign({}, row)
          this.dialogLeftTop1_1 = !this.dialogLeftTop1_1
        },
        operationEvent1_1(row) {
          console.log(row)
          this.previewData = row
          this.dialogLeftTop1_2 = !this.dialogLeftTop1_2
        },
        operationEvent1_2(row) {
          this.$confirm('此操作将永久删除该条信息, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            remove({ id: row.id }).then(() => {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
              this.handleFilter(this.listQuery)
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
        }
      }
    }
</script>

<style lang="scss">
.wrap{
        
    .flexWrap{
        display: flex;
        height: 100%;
        background-color: #fff;
        overflow-y: scroll;
        overflow-x: hidden;
        .leftWrap{
            flex: 10;
        }
        .rightWrap{
            flex: 2;
        }
    }


    .filterBox{
        display: flex;
        justify-content: space-between;
        align-items: center;
        .filterPart{
        line-height: 2;
        }
    }
    .dialogLeftTop1_1{
        .el-select{
            display: block;
        }
    }
    .editor-container {
        min-height: 500px;
        margin: 0 0 30px;
        .editor-upload-btn-container {
            text-align: right;
            margin-right: 10px;
            .editor-upload-btn {
                display: inline-block;
            }
        }
      }
}
</style>
